package com.itcast.donkey.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.modles.DetailedTravel_area_Modles;

import org.xutils.x;

/**
 * Created by lanouhn on 16/8/31.
 */
public class DetailedTravelInContentAdapter extends RecyclerView.Adapter<DetailedTravelInContentAdapter.InContentViewHolder> {

    private Context context;
    private DetailedTravel_area_Modles.AttractionTripTagsBean.AttractionContentsBean contentsBean;
    private int count;

    public DetailedTravelInContentAdapter(Context context, DetailedTravel_area_Modles.AttractionTripTagsBean.AttractionContentsBean contentsBean) {
        this.context = context;
        this.contentsBean = contentsBean;
        this.count = contentsBean.getNotes().size() + 1;
    }

    @Override
    public InContentViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_detailed_travel_in_content, null);
        InContentViewHolder holder = new InContentViewHolder(view);
        return holder;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(InContentViewHolder holder, int position) {

        if (position == 0) {
            holder.ivItemInContentIcon.setVisibility(View.VISIBLE);
            holder.tvItemInContentTitle.setVisibility(View.VISIBLE);
            holder.tvItemInContentContent.setVisibility(View.VISIBLE);
            x.image().bind(holder.ivItemInContentIcon, contentsBean.getTrip().getUser().getImage());
            holder.tvItemInContentTitle.setText(contentsBean.getTrip().getUser().getName());
            holder.tvItemInContentContent.setText(contentsBean.getDescription());
        } else {
            int i = position - 1;
            holder.ivItemInContentImage.setVisibility(View.VISIBLE);
            x.image().bind(holder.ivItemInContentImage, contentsBean.getNotes().get(i).getPhoto_url());
            if (!"".equals(contentsBean.getNotes().get(i).getDescription())) {
                holder.tvItemInContentExplain.setVisibility(View.VISIBLE);
                holder.tvItemInContentExplain.setText(contentsBean.getNotes().get(i).getDescription());
            }

        }

    }

    @Override
    public int getItemCount() {
        return count;
    }

    public class InContentViewHolder extends RecyclerView.ViewHolder {
        private ImageView ivItemInContentIcon;
        private TextView tvItemInContentTitle;
        private TextView tvItemInContentContent;
        private ImageView ivItemInContentImage;
        private TextView tvItemInContentExplain;

        public InContentViewHolder(View itemView) {
            super(itemView);
            ivItemInContentIcon = (ImageView) itemView.findViewById(R.id.iv_item_in_content_icon);
            tvItemInContentTitle = (TextView) itemView.findViewById(R.id.tv_item_in_content_title);
            tvItemInContentContent = (TextView) itemView.findViewById(R.id.tv_item_in_content_content);
            ivItemInContentImage = (ImageView) itemView.findViewById(R.id.iv_item_in_content_image);
            tvItemInContentExplain = (TextView) itemView.findViewById(R.id.tv_item_in_content_explain);
        }
    }
}
